﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Management;

namespace BingWallPaper
{
    sealed class Utils
    {
        public static bool IsEwfActive()
        {
//0 = Boot
//1 = System
//2 = Automatic
//3 = Manual
//4 = Disabled

            object o = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ewf", "Start", null);
            if (null == o) return false;
            //
            try
            {
                int n = (int)o;
                if (0 == n) return true;
            }
            catch
            {
                return false;
            }

            //
            //[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ewf]
            //"ErrorControl"=dword:00000001
            //"Group"="System Bus Extender"
            //"Start"=dword:00000000
            //"Type"=dword:00000001
            //WriteRegValue(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Services\ewf", RegistryValueKind.DWord, "ErrorControl", 1);
            //WriteRegValue(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Services\ewf", RegistryValueKind.String, "Group", "System Bus Extender");
            //WriteRegValue(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Services\ewf", RegistryValueKind.DWord, "Start", 0);
            //WriteRegValue(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Services\ewf", RegistryValueKind.DWord, "Type", 1);

            return false;
        }


        public static bool HasWirelessNetwork()
        {
            ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_NetworkAdapter Where AdapterType='Wireless'");
            foreach (ManagementObject mo in mos.Get())
            {
                if(22 == (uint)mo["ConfigManagerErrorCode"])continue;//Device is disabled.
                return true;
            }
            return false;
        }

    }//class
}//namespace
